package com.dayu.finecomm.aop;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * AOP日志织入点
 * 
 * @author XuJialiang
 * @since 2017-11-10 14:45:15
 * @version V1.0.0
 */
public class MethodInterceptorAdvice implements MethodInterceptor {
	static Logger LOGGER = LoggerFactory
			.getLogger(MethodInterceptorAdvice.class);

	@Override
	public Object invoke(MethodInvocation invocation) throws Throwable {
		// TODO Auto-generated method stub
		Object retVal = null;

		try {
			Long reqTime = System.currentTimeMillis();

			retVal = invocation.proceed();

			Long rspTime = System.currentTimeMillis();

			AopProxy.instance().getAopLogManager()
					.insertAopLog(invocation, retVal, reqTime, rspTime);
		} catch (Exception e) {
			LOGGER.error("MethodInterceptorAdvice invoke error: " + e);
		}

		return retVal;
	}
}
